#include "color.hpp"


void Material::ParsePtree ( ptree &tree )
{
    diffuse.r = tree.get< real_t>("diffuse.r");
    diffuse.g = tree.get< real_t>("diffuse.g");
    diffuse.b = tree.get< real_t>("diffuse.b");
    
    
    spectecular.r = tree.get< real_t>("spectecular.r") ;
    spectecular.g = tree.get< real_t>("spectecular.g") ;
    spectecular.b = tree.get< real_t>("spectecular.b") ;
    
    real_t max_c;    
    if ( spectecular.r > spectecular.g)
    {
        if ( spectecular.r > spectecular.b)
        {
            max_c = spectecular.r;
        }
        else
        {
            max_c = spectecular.b;
        }
    }
    else
    {
        if ( spectecular.g > spectecular.b)
        {
            max_c = spectecular.g;
        }
        else
        {
            max_c = spectecular.b;
        }
    }

    if ( max_c > 0.5)
    {
        max_c = 0.5/max_c;
        spectecular.r *= max_c;
        spectecular.g *= max_c;
        spectecular.b *= max_c;
    }
    
    
    spect_pow = tree.get< real_t>("spectecular_pow");
    
    n = tree.get< real_t>("n");
    opacity    = tree.get< real_t>("opacity");
    reflection = tree.get< real_t>("reflection");
}